import React, {Component} from "react";
import {
    View,
    Text,
    Image,
    TouchableOpacity,
    StyleSheet,
    AsyncStorage,
} from 'react-native';
import ListViewTest from "../common/ListViewTest"

let dataSignin = [
    {
        "title": "登陆",
        "icon": "ios-log-in",
        "color": "#f6a623",
        "type": "info",
    },
    {
        "title": "还没有账号?",
        "icon": "md-help-circle",
        "color": "#78bef5",
        "type": "info",
    },
];

let dataSignout = [
    {
        "title": "我的信息",
        "icon": "ios-card-outline",
        "color": "#f6a623",
        "type": "info",
        "name": "myInfo"
    },
    {
        "title": "退出账号",
        "icon": "ios-log-out-outline",
        "color": "#78bef5",
        "type": "info",
        "name": "signout"
    },
];

export default class MyInfo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            name: '用户名',
            data: []
        }
    }

    componentWillMount() {
        this.getData()
    }

    getData() {
        AsyncStorage.getItem('user', (err, ret) => {
            this.setState({
                data: !!ret ? dataSignout : dataSignin,
                name: JSON.parse(ret).name
            })
        })
    }

    componentWillUpdate() {
        this.getData()
    }

    render() {
        return (
            <View style={styles.container}>
                <View style={styles.name}>
                    <Image source={require("../../res/images/ic_my.png")}></Image>
                    <Text style={styles.text}>{this.state.name}</Text>
                </View>
                <ListViewTest
                    data={this.state.data}
                    navigation={this.props.navigation}
                />
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: "white",
    },
    text: {
        fontSize: 17,
        color: "#000",
        paddingTop: 10
    },
    name: {
        height: 150,
        backgroundColor: "#dfdfdf",
        justifyContent: "center",
        alignItems: "center",
    }
})